package funjava;

/**
 * Created by judasnow on 5/16/16.
 */

final class Pointer {
    // final 变量在类体内被初始化之后 还能否修改其值?
    private final int x;
    private final int y;

    private int z;
    public Pointer(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public Pointer() {
        x = 0;
        y = 0;
    }
    public int getX() {
        return x;
    }
    public int getY() {
        return y;
    }

    // 以下两个是直接返回对象的版本
    public Pointer translate(int xDelta, int yDelta) {
        return new Pointer(x + xDelta, y + yDelta);
    }
    public Pointer scale(int d) {
        return new Pointer(x * d, y * d);
    }

    // 以下两个版本进行本地修改
    // public void translate(int xDelta, int yDelta) {
    //    this.x = x + xDelta;
    //    this.y = y + yDelta;
    // }
}

public class C2_5 {
    public static void main(String[] args) {
        Pointer p = new Pointer(3, 4).translate(1, 3).scale(5);
    }
}
